//
// Created by 86150 on 2021/10/9.
//

#ifndef BJUT_CPP_2_PRODUCTS_H
#define BJUT_CPP_2_PRODUCTS_H
#include "prototype.h"

class technician final: public employee
{
	protected:
		int work_hour;
		void count() override { salary = work_hour * 100; }

	public:
		technician(std::string id1, std::string name1, int hours):
			employee(id1, name1), work_hour(hours) {}
};

class manager: public virtual employee
{
	protected:
		int solid_salary;
		void count() override { salary = solid_salary; }

	public:
		manager(std::string id1, std::string name1, int ss):
			employee(id1, name1), solid_salary(ss) {}
};

class salesman: public virtual employee
{
	protected:
		int sale_amount;
		void count() override { salary = sale_amount * 0.04; }

	public:
		salesman(std::string id1, std::string name1, int sa):
			employee(id1, name1), sale_amount(sa) {}
};

class salesmanager final: public manager, salesman
{
	protected:
		void count() override { salary = solid_salary + sale_amount * 0.05; }

	public:
		salesmanager(std::string id2, std::string name2, int ss1, int sa1):
			employee(id2, name2),
			manager(id2, name2, ss1),
			salesman(id2, name2, sa1) {}
};

class common_employee
{
	private:
		technician* r_tech;
		manager* r_mg;
		salesman* r_slman;
		salesmanager* r_slmg;

	public:
		common_employee():
			r_tech(NULL), r_mg(NULL), r_slman(NULL), r_slmg(NULL) {};
		common_employee(std::string id_, std::string name_,
						std::string kind, int hours_, int solids, int sale):
						r_tech(NULL), r_mg(NULL), r_slman(NULL), r_slmg(NULL)
		{
			if (kind == "technician") r_tech = new technician(id_, name_, hours_);
			if (kind == "manager") r_mg = new manager(id_, name_, solids);
			if (kind == "salesman") r_slman = new salesman(id_, name_, sale);
			if (kind == "salesmanager") r_slmg = new salesmanager(id_, name_, solids, sale);
		}
		std::string get_id() const
		{
			if (r_tech != NULL) return r_tech->get_id();
			if (r_mg != NULL) return r_mg->get_id();
			if (r_slman != NULL) return r_slman->get_id();
			if (r_slmg != NULL) return r_slmg->get_id();
			return "";
		}
		std::string get_name() const
		{
			if (r_tech != NULL) return r_tech->get_name();
			if (r_mg != NULL) return r_mg->get_name();
			if (r_slman != NULL) return r_slman->get_name();
			if (r_slmg != NULL) return r_slmg->get_name();
			return "";
		}
		int get_salary()
		{
			if (r_tech != NULL) return r_tech->get_salary();
			if (r_mg != NULL) return r_mg->get_salary();
			if (r_slman != NULL) return r_slman->get_salary();
			if (r_slmg != NULL) return r_slmg->get_salary();
			return 0;
		}
		std::string get_kind() const
		{
			if (r_tech != NULL) return "technician";
			if (r_mg != NULL) return "manager";
			if (r_slman != NULL) return "salesman";
			if (r_slmg != NULL) return "salesmanager";
			return "";
		}
		common_employee& operator = (common_employee& another)
		{
			if (another.r_tech != NULL) r_tech = new technician(*another.r_tech);
			if (another.r_mg != NULL) r_mg = new manager(*another.r_mg);
			if (another.r_slman != NULL) r_slman = new salesman(*another.r_slman);
			if (another.r_slmg != NULL) r_slmg = new salesmanager(*another.r_slmg);
			return *this;
		}
		void set_salary(int new_salary)
		{
			if (r_tech != NULL) r_tech->set_salary(new_salary);
			if (r_mg != NULL) r_mg->set_salary(new_salary);
			if (r_slman != NULL) r_slman->set_salary(new_salary);
			if (r_slmg != NULL) r_slmg->set_salary(new_salary);
		}
		~common_employee()
		{
			if (r_tech != NULL) delete r_tech;
			if (r_mg != NULL) delete r_mg;
			if (r_slman != NULL) delete r_slman;
			if (r_slmg != NULL) delete r_slmg;
		}
};
#endif //BJUT_CPP_2_PRODUCTS_H
